package com.ygp.monitor;

/**
 * <Description> <br>
 *
 * @author linmiaolai@sanyygp.com<br>
 * @version 1.0<br>
 * @date 2021/09/14 <br>
 */
public class MonitorExample {
    private int a = 0;

    public synchronized void writer() { // 1
        a++; // 2
    } // 3

    public synchronized void reader() { // 4
        int i = a; // 5
    } // 6


    public synchronized Object get(long millis) throws InterruptedException {
        long future = System.currentTimeMillis() + millis;
        long remaining = millis;
        Object result = null;
        while ((result == null) && remaining >= 0) {
            wait(remaining);
            remaining = future - System.currentTimeMillis();
            result = "xxx";
        }
        return result;
    }
}
